<template>
  <div class="commentsList">
    <div>
      <span class="iconfont icon-xiangzuo" @click="returnGo"></span>评论
    </div>
    <div class="MiniPlayer" v-if="SongDetail">
      <div
        :style="'background-image: url(' + SongDetail.al.picUrl + ')'"
        class="BackgroundRecord"
      ></div>
      <div class="SongDetail-name">
        {{ SongDetail.name
        }}<span>&nbsp;-&nbsp;{{ SongDetail.ar[0].name }}&nbsp;&nbsp;</span
        >
      </div>
    </div>
    <div class="Comment-area">
      <div>评论区</div>
    </div>
    <van-tabs v-model="activeName">
      <van-tab title="推荐" name="a">
        <div class="Comment-content">
          <div
            v-for="(item, index) in CommentMusic"
            :key="index"
            class="CommentMusic"
          >
            <div
              class="backgroundImage"
              :style="'background-image: url(' + item.user.avatarUrl + ')'"
            ></div>
            <div class="nickname">
              <h1>{{ item.user.nickname }}</h1>
              <h2>{{ item.timeStr }}</h2>
            </div>
            <div class="give-the-thumbs-up" @click="givethesType(item)">
              {{ item.likedCount }}
              <span v-show="!item.liked" class="iconfont icon-dianzan"></span>
              <span
                v-show="item.liked"
                class="iconfont icon-dianzan iconfontred"
              ></span>
            </div>
            <div class="content">
              <p>{{ item.content }}</p>
            </div>
          </div>
        </div>
      </van-tab>
      <van-tab title="最热" name="b"
        ><div class="Comment-content">
          <div
            v-for="(item, index) in CommenHot"
            :key="index"
            class="CommentMusic"
          >
            <div
              class="backgroundImage"
              :style="'background-image: url(' + item.user.avatarUrl + ')'"
            ></div>
            <div class="nickname">
              <h1>{{ item.user.nickname }}</h1>
              <h2>{{ item.timeStr }}</h2>
            </div>
            <div class="give-the-thumbs-up" @click="givethesType(item)">
              {{ item.likedCount }}
              <span v-show="!item.liked" class="iconfont icon-dianzan"></span>
              <span
                v-show="item.liked"
                class="iconfont icon-dianzan iconfontred"
              ></span>
            </div>
            <div class="content">
              <p>{{ item.content }}</p>
            </div>
          </div>
        </div></van-tab
      >
      <van-tab title="最新" name="c"
        ><div class="Comment-content">
          <div
            v-for="(item, index) in CommentMusic"
            :key="index"
            class="CommentMusic"
          >
            <div
              class="backgroundImage"
              :style="'background-image: url(' + item.user.avatarUrl + ')'"
            ></div>
            <div class="nickname">
              <h1>{{ item.user.nickname }}</h1>
              <h2>{{ item.timeStr }}</h2>
            </div>
            <div class="give-the-thumbs-up" @click="givethesType(item)">
              {{ item.likedCount }}
              <span v-show="!item.liked" class="iconfont icon-dianzan"></span>
              <span
                v-show="item.liked"
                class="iconfont icon-dianzan iconfontred"
              ></span>
            </div>
            <div class="content">
              <p>{{ item.content }}</p>
            </div>
          </div>
        </div></van-tab
      >
    </van-tabs>
    <div class="AddComment">
      <input type="text" placeholder="输入热评" v-model="sr" /><span
        class="iconfont icon-wangyiyunyinle1-copy"
      ></span>
      <p @click="Comment">发送</p>
    </div>
  </div>
</template>
<script>
import { getSongDetail } from "../api/mixed";
import { Toast } from "vant";
import {
  getCommentMusic,
  getCommenLikeId,
  getCommenHot,
  getComment,
} from "../api/recommend";
export default {
  data() {
    return {
      SongDetail: null, //歌曲信息
      CommentMusic: null,
      activeName: "a",
      CommenHot: null,
      sr: null,
    };
  },
  methods: {
    returnGo() {
      this.$router.go("-1");
    },
    Comment() {
      getComment({
        type: 0,
        id: this.SongDetail.al.id,
        content: this.sr,
      });
      this.sr = null;
    },
    // 获取歌曲信息
    getSongDetailFun() {
      getSongDetail({ ids: this.$route.query.playerId }).then((data) => {
        this.SongDetail = data.songs[0];
      });
    },
    //点赞
    givethesType(item) {
      console.log(item.liked);
      item.liked = !item.liked;
      if (item.liked) {
        Toast("点赞成功");
        getCommenLikeId({
          id: this.$route.query.playerId,
          cid: item.commentId,
          t: 1,
          type: 0,
        });
      } else {
        Toast("取消点赞");
        getCommenLikeId({
          id: this.$route.query.playerId,
          cid: item.commentId,
          t: 0,
          type: 0,
        });
      }
    },
  },
  created() {
    this.getSongDetailFun();
    getCommentMusic({ id: this.$route.query.playerId }).then((data) => {
      this.CommentMusic = data.comments;
    });
    getCommenHot({ id: this.$route.query.playerId }).then((data) => {
      this.CommenHot = data.hotComments;
    });
  },
};
</script>
<style lang="less">
.commentsList {
  .MiniPlayer {
    padding-top: 5%;
    width: 100%;
    margin: 0 auto;
    height: 10vh;
    display: flex;
    align-items: center;
    border-bottom: 8px solid #f7f7f7;
    .BackgroundRecord {
      width: 45px;
      height: 45px;
      border-radius: 50%;
      background-size: 100%;
      border: 10px solid #000;
      margin: 0 5%;
    }
    .SongDetail-name {
      span {
        color: #7f7f7f;
      }
      .follow {
        color: red;
      }
    }
  }
  .Comment-area {
    margin: 10px 0;
    text-align: center;
  }
  .Comment-content {
    width: 100%;
    padding-bottom: 8%;
    .CommentMusic {
      margin-top: 10px;
      width: 95%;
      padding-left: 3%;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      .backgroundImage {
        width: 38px;
        height: 38px;
        background-size: 100%;
        border-radius: 50%;
        margin-right: 2%;
      }
      .nickname {
        flex: 1;
        color: #838383;
      }
      h1 {
        font-size: 14px;
      }
      h2 {
        font-size: 8px;
      }
      .give-the-thumbs-up {
        position: relative;
        padding-right: 5%;
        line-height: 12px;
        font-size: 12px;
        color: #838383;
        span {
          position: absolute;
          right: -2%;
          color: #838383;
        }
        .iconfontred {
          color: red;
        }
      }
      .content {
        margin-top: 1%;
        width: 88%;
        margin-left: 12%;
        font-size: 14px;
        border-bottom: 1px solid #b4b4b4;
        padding-bottom: 2%;
      }
    }
  }
  .AddComment {
    position: fixed;
    bottom: 0px;
    width: 100%;
    height: 40px;
    border-top: 1px solid #838383;
    background-color: white;
    display: flex;
    align-items: center;
    z-index: 10;
    input {
      width: 80%;
      height: 100%;
      padding-left: 20px;
      border: none;
    }
    span {
      font-size: 20px;
      color: red;
    }
  }
}
</style>